package com.lovingtour.manager.merchant.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lovingtour.manager.R;
import com.lovingtour.manager.entity.CateringMenuEntity;
import com.lovingtour.manager.util.ApplicationUtils;

public class MerchantServiceListAdapter extends BaseAdapter{

	private ArrayList<com.lovingtour.manager.entity.CateringMenuEntity> dataSources;
	private LayoutInflater inflater;
	public MerchantServiceListAdapter(Context context,ArrayList<CateringMenuEntity> dataSources){
		inflater = LayoutInflater.from(context);
		setDataSources(dataSources)
		;
	}
	
	public void setDataSources(ArrayList<CateringMenuEntity> dataSources){
		if (dataSources!=null) {
			this.dataSources = dataSources;
		}else {
			this.dataSources = new ArrayList<CateringMenuEntity>();
		}
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return dataSources.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return dataSources.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
	    ViewHolder holder = null;
		if (convertView==null) {
			convertView = inflater.inflate(R.layout.merchant_servicelist_item, parent, false);
			holder = new ViewHolder();
			holder.tvCost = (TextView) convertView.findViewById(R.id.item_money);
			holder.tvName = (TextView) convertView.findViewById(R.id.item_name);
			convertView.setTag(holder);
		}else {
			holder = (ViewHolder) convertView.getTag();
		}
		CateringMenuEntity entity = dataSources.get(position);
		holder.tvCost.setText(ApplicationUtils.format2Renminbi(entity.getCost()));
		holder.tvName.setText(entity.getName());
		return convertView;
	}

	class ViewHolder{
		TextView tvName;
		TextView tvCost;
	}
}
